import Vue from 'vue'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n
import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

// 全局注册组件
import UploadImg from '@/components/UploadImg/index.vue'
Vue.component('UploadImg', UploadImg)
// 头像组件
import ImageHolder from '@/components/ImageHolder/index.vue'
Vue.component('ImageHolder', ImageHolder)

// 导入excle
import UploadExcel from '@/components/UploadExcel'
Vue.component('UploadExcel', UploadExcel) // 注册导入excel组件

import '@/icons' // icon
import '@/permission' // permission control
// 面包屑组件 全局注册
import PageTools from '@/components/PageTools'
Vue.component(PageTools.name, PageTools)

// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
Vue.config.productionTip = false
// 全屏 组件
import ScreenFull from './components/ScreenFull/index.vue'
Vue.component('ScreenFull', ScreenFull)
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
// * <el-button v-allow="'export_excel'">导出excel</el-button>
//  * 如果 points 中有export_excel,则按钮会显示，否则按钮不显示
//  *
//  * <el-button v-allow="'import_excel'">导入excel</el-button>
//  * 如果 points 中有import_excel,则按钮会显示，否则按钮不显示
//  */
// 自定义指令
Vue.directive('allow', {
  // el是当前的dom元素
  inserted(el, binding) {
    const points = store.state.user.userInfo.roles.points

    console.log(el, points, binding.value)
    if (points.includes(binding.value)) {
      // el.style.display = 'block'
    } else {
      // el.style.display = 'none'
      // 删除这个元素
      el.parentNode.removeChild(el)
    }
  }
})
// 国际化语言
import i18n from '@/lang'

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
